

declare let $:any;

/**
 * 模块对话框(基于Jquery和bootstrap)
 * 级别:实体类(m),通用(c)
 */
export class mc_dialog{
    public title:string="";
    public message:string="";
    public id:string="dialog";

    /**
     * 弹出提示框
     * @param id
     * @param classList
     */
    public show(...classList:string[]){
        let dialog=$("#"+this.id);
        let $DivTitle=dialog.find("div.modal-header").eq(0);

        $DivTitle.find("h4").remove();
        let h4=document.createElement("h4");
        h4.innerText=this.title;
        h4.classList.add("modal-title");
        if(classList&&classList.length>0) h4.classList.add.apply(h4.classList,classList);
        $DivTitle[0].appendChild(h4);

        let divContent=dialog.find("div.modal-body").eq(0)[0];
        divContent.innerHTML="";

        let htmlMessage=this.message||"";

        if(htmlMessage.includes("\r\n"))
        {
            htmlMessage=htmlMessage.split("\r\n").map((s)=>"<p>"+s+"</p>").join("");
        }
        else {
            htmlMessage="<p>"+htmlMessage+"</p>";
        }

        divContent.innerHTML=htmlMessage;

        if(classList&&classList.length>0){
            divContent.classList.add.apply(divContent.classList,classList);
        }
        dialog.modal("show");
    }

    public successShow(message:string=""){
        this.title="成功";
        message=(message||"").trim();
        if(message!="") this.message=message;
        this.show("success-color");

    }

    public dangerShow(message:string=""){
        this.title="错误";
        message=(message||"").trim();
        if(message!="") this.message=message;
        this.show("danger-color");
    }

    public warmingShow(message:string=""){
        this.title="警告";
        message=(message||"").trim();
        if(message!="") this.message=message;
        this.show("warning-color");
    }


}